extends Area2D

@export var slime_speed : float = -50

var is_death : bool = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
	if is_death :
		return
	position += Vector2(slime_speed,0) * delta
	
	if position.x < -251:
		queue_free()


func _on_body_entered(body: Node2D) -> void:
	if body is CharacterBody2D and not is_death:
		body.game_over()


func _on_area_entered(area: Area2D) -> void:
	if area.is_in_group("bullet"):
		$AnimatedSprite2D.play("death")
		$AudioStreamPlayer.play()
		is_death = true
		area.queue_free()
		# 添加得分
		get_tree().current_scene.score += 1
		# 延遲一秒后銷毀
		await get_tree().create_timer(1).timeout
		queue_free()
		
